﻿using SIG.Infrastructure;
using SIG.Infrastructure.Configs;
using SIG.Infrastructure.Extensions;
using SIG.WeiXin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace SIG.Web.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            string nonceStr = Guid.NewGuid().ToString();
            long timestamp = DateTime.Now.ToJavaScriptMilliseconds();
            ViewBag.timestamp = timestamp;
            ViewBag.nonceStr = nonceStr;      
            WXHelper.GetAccessToken();
            ViewBag.AccessToken = SettingsManager.WeiXin.AccessToken;
            WXHelper.GetJsapiTicket();

            string tempStr = $"jsapi_ticket={SettingsManager.WeiXin.JsapiTicket}&noncestr={nonceStr}&timestamp={timestamp}&url={Request.RawUrl}";
            ViewBag.signature = Encryption.GetSwcSHA1(tempStr);
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}